# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple aarch64 -verify-machineinstrs -run-pass=legalizer -debugify-and-strip-all-safe %s -o - | FileCheck %s

---
name:            narrow_scalar_uaddo_s128
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: narrow_scalar_uaddo_s128
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
    ; CHECK: [[COPY2:%[0-9]+]]:_(s64) = COPY $x2
    ; CHECK: [[COPY3:%[0-9]+]]:_(s64) = COPY $x3
    ; CHECK: [[UADDO:%[0-9]+]]:_(s64), [[UADDO1:%[0-9]+]]:_(s1) = G_UADDO [[COPY]], [[COPY2]]
    ; CHECK: %17:_(s64), %carry_out:_(s1) = G_UADDE [[COPY1]], [[COPY3]], [[UADDO1]]
    ; CHECK: %carry_out_ext:_(s64) = G_ANYEXT %carry_out(s1)
    ; CHECK: $x0 = COPY [[UADDO]](s64)
    ; CHECK: $x1 = COPY %17(s64)
    ; CHECK: $x2 = COPY %carry_out_ext(s64)
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %2:_(s64) = COPY $x2
    %3:_(s64) = COPY $x3
    %lhs:_(s128) = G_MERGE_VALUES %0, %1
    %rhs:_(s128) = G_MERGE_VALUES %2, %3
    %add:_(s128), %carry_out:_(s1) = G_UADDO %lhs, %rhs
    %add0:_(s64), %add1:_(s64) = G_UNMERGE_VALUES %add
    %carry_out_ext:_(s64) = G_ANYEXT %carry_out
    $x0 = COPY %add0
    $x1 = COPY %add1
    $x2 = COPY %carry_out_ext

...
---
name:            narrow_scalar_uaddo_big_nonpow2
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: narrow_scalar_uaddo_big_nonpow2
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
    ; CHECK: [[COPY2:%[0-9]+]]:_(s64) = COPY $x2
    ; CHECK: [[COPY3:%[0-9]+]]:_(s64) = COPY $x3
    ; CHECK: [[UADDO:%[0-9]+]]:_(s64), [[UADDO1:%[0-9]+]]:_(s1) = G_UADDO [[COPY]], [[COPY1]]
    ; CHECK: [[UADDE:%[0-9]+]]:_(s64), [[UADDE1:%[0-9]+]]:_(s1) = G_UADDE [[COPY1]], [[COPY2]], [[UADDO1]]
    ; CHECK: %22:_(s64), %carry_out:_(s1) = G_UADDE [[COPY2]], [[COPY3]], [[UADDE1]]
    ; CHECK: %carry_out_ext:_(s64) = G_ANYEXT %carry_out(s1)
    ; CHECK: $x0 = COPY [[UADDO]](s64)
    ; CHECK: $x1 = COPY [[UADDE]](s64)
    ; CHECK: $x2 = COPY %22(s64)
    ; CHECK: $x3 = COPY %carry_out_ext(s64)
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %2:_(s64) = COPY $x2
    %3:_(s64) = COPY $x3
    %lhs:_(s192) = G_MERGE_VALUES %0, %1, %2
    %rhs:_(s192) = G_MERGE_VALUES %1, %2, %3
    %add:_(s192), %carry_out:_(s1) = G_UADDO %lhs, %rhs
    %add0:_(s64), %add1:_(s64), %add2:_(s64) = G_UNMERGE_VALUES %add
    %carry_out_ext:_(s64) = G_ANYEXT %carry_out
    $x0 = COPY %add0
    $x1 = COPY %add1
    $x2 = COPY %add2
    $x3 = COPY %carry_out_ext

...
---
name:            test_scalar_uaddo_small
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: test_scalar_uaddo_small
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
    ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
    ; CHECK: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK: [[AND:%[0-9]+]]:_(s32) = G_AND [[TRUNC]], [[C]]
    ; CHECK: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
    ; CHECK: [[AND1:%[0-9]+]]:_(s32) = G_AND [[TRUNC1]], [[C]]
    ; CHECK: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[AND]], [[AND1]]
    ; CHECK: [[TRUNC2:%[0-9]+]]:_(s8) = G_TRUNC [[ADD]](s32)
    ; CHECK: [[COPY2:%[0-9]+]]:_(s32) = COPY [[ADD]](s32)
    ; CHECK: [[AND2:%[0-9]+]]:_(s32) = G_AND [[COPY2]], [[C]]
    ; CHECK: [[ICMP:%[0-9]+]]:_(s32) = G_ICMP intpred(ne), [[ADD]](s32), [[AND2]]
    ; CHECK: [[COPY3:%[0-9]+]]:_(s8) = COPY [[TRUNC2]](s8)
    ; CHECK: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[ADD]](s32)
    ; CHECK: [[ANYEXT1:%[0-9]+]]:_(s64) = G_ANYEXT [[ICMP]](s32)
    ; CHECK: $x0 = COPY [[ANYEXT]](s64)
    ; CHECK: $x1 = COPY [[ANYEXT1]](s64)
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %2:_(s8) = G_TRUNC %0(s64)
    %3:_(s8) = G_TRUNC %1(s64)
    %4:_(s8), %5:_(s1) = G_UADDO %2, %3
    %6:_(s64) = G_ANYEXT %4(s8)
    %7:_(s64) = G_ANYEXT %5(s1)
    $x0 = COPY %6(s64)
    $x1 = COPY %7(s64)

...
---
name:            test_scalar_uaddo_32
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: test_scalar_uaddo_32
    ; CHECK: %lhs:_(s32) = COPY $w0
    ; CHECK: %rhs:_(s32) = COPY $w1
    ; CHECK: %add:_(s32), %carry_out:_(s1) = G_UADDO %lhs, %rhs
    ; CHECK: %carry_out_ext:_(s32) = G_ANYEXT %carry_out(s1)
    ; CHECK: $w0 = COPY %add(s32)
    ; CHECK: $w1 = COPY %carry_out_ext(s32)
    %lhs:_(s32) = COPY $w0
    %rhs:_(s32) = COPY $w1
    %add:_(s32), %carry_out:_(s1) = G_UADDO %lhs, %rhs
    %carry_out_ext:_(s32) = G_ANYEXT %carry_out
    $w0 = COPY %add
    $w1 = COPY %carry_out_ext

...
